<?php

/**
 * This is the model class for table "page".
 *
 * The followings are the available columns in table 'page':
 * @property string $id
 * @property string $type
 * @property string $title
 * @property string $quote
 * @property string $content
 * @property string $thumbnail
 * @property integer $status
 * @property string $desc
 * @property string $date_created
 * @property string $date_edited
 * @property string $seo_link
 * @property string $seo_keyword
 * @property string $seo_description
 */
class Page extends CActiveRecord
{
	public $parent_id;
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Page the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'page';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('type, title, date_created', 'required'),
			array('status', 'numerical', 'integerOnly'=>true),
			array('type', 'length', 'max'=>30),
			array('title', 'length', 'max'=>200),
			array('quote, content, thumbnail, desc, date_edited, seo_link, seo_keyword, seo_description', 'safe'),
			array('thumbnail', 'file',
					'types'=>'jpg,jpeg,png',
					'maxSize'=>1024 * 1024 * 5, // 5MB
					'tooLarge'=>'The file was larger than 5MB. Please upload a smaller file.',
					'allowEmpty'=>1,
			),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, parent_id, type, title, quote, content, thumbnail, status, desc, date_created, date_edited, seo_link, seo_keyword, seo_description', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => Yii::t('app', 'ID'),
			'parent_id' => Yii::t('app', 'Page Parent ID'),
			'type' => Yii::t('app', 'Type'),
			'title' => Yii::t('app', 'Title'),
			'quote' => Yii::t('app', 'Quote'),
			'content' => Yii::t('app', 'Content'),
			'thumbnail' => Yii::t('app', 'Thumbnail'),
			'status' => Yii::t('app', 'Status'),
			'desc' => Yii::t('app', 'Desc'),
			'date_created' => Yii::t('app', 'Date Created'),
			'date_edited' => Yii::t('app', 'Date Edited'),
			'seo_link' => Yii::t('app', 'Seo Link'),
			'seo_keyword' => Yii::t('app', 'Seo Keyword'),
			'seo_description' => Yii::t('app', 'Seo Description'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('type',$this->type,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('quote',$this->quote,true);
		$criteria->compare('content',$this->content,true);
		$criteria->compare('thumbnail',$this->thumbnail,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('desc',$this->desc,true);
		$criteria->compare('date_created',$this->date_created,true);
		$criteria->compare('date_edited',$this->date_edited,true);
		$criteria->compare('seo_link',$this->seo_link,true);
		$criteria->compare('seo_keyword',$this->seo_keyword,true);
		$criteria->compare('seo_description',$this->seo_description,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public static function listType() {
		return array(
					'about' => Yii::t('app', 'About'),
					'career' => Yii::t('app', 'Career'),
					'other' => Yii::t('app', 'Page other'),
				);
	}
}